Skip to content

toolchain: precheck passes under the pre-commit hook from a worktree - #1807

Open
sbryngelson wants to merge 2 commits into
MFlowCode:masterfrom
sbryngelson:fix/precheck-under-git-hooks
Open

toolchain: precheck passes under the pre-commit hook from a worktree#1807
sbryngelson wants to merge 2 commits into
MFlowCode:masterfrom
sbryngelson:fix/precheck-under-git-hooks

Conversation

@sbryngelson

Copy link
Copy Markdown
Member

Committing from a git worktree fails the pre-commit hook: git exports GIT_DIR and GIT_INDEX_FILE to hooks, and neither cwd nor git -C overrides them, so the throwaway repositories in test_coverage_unit.py end up querying the committing repository instead. Two tests fail (test_verified_after_last_change_*) and the commit is blocked, leaving --no-verify as the only way through.

The test file already scrubbed GIT_* for its own setup calls. This moves that scrub into coverage._git and routes the three raw git calls in check_coverage_map_health.py through it, so every git subprocess the coverage machinery makes targets the directory it was given.

Verified by making this commit through the hook from a worktree: precheck passes, the two tests pass under the hook's environment, and the full toolchain suite is 583 passed.

Copilot AI lite review requested due to automatic review settings September 2, 2026 21:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Pull request overview

Fixes failures when running the coverage toolchain under a git hook launched from a worktree by ensuring git subprocesses ignore inherited GIT_* hook environment variables and operate on the intended repository directory.

Changes:

  • Centralized “scrub GIT_* from environment” logic into mfc.test.coverage and applied it to the shared git runner.
  • Updated check_coverage_map_health.py to route its git invocations through the centralized helper.
  • Removed the duplicated env-scrub helper from test_coverage_unit.py and imported the shared one instead.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
toolchain/mfc/test/test_coverage_unit.py Removes local _env_without_git helper and imports the shared implementation from mfc.test.coverage.
toolchain/mfc/test/coverage.py Introduces _env_without_git() and applies it in _git() so git calls don’t inherit hook-provided GIT_* variables.
.github/scripts/check_coverage_map_health.py Switches raw subprocess.run(["git", ...]) calls to use the shared _git() helper.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.


sys.path.insert(0, str(Path(__file__).resolve().parents[2] / "toolchain"))
from mfc.test.coverage import COVERAGE_MAP_PATH, load_map, map_health # noqa: E402
from mfc.test.coverage import COVERAGE_MAP_PATH, _git, load_map, map_health # noqa: E402
Comment on lines +220 to +222
# Git exports GIT_DIR and GIT_INDEX_FILE to hooks, and neither cwd nor `git -C` overrides them:
# under the pre-commit hook every call below would otherwise act on the committing repository.
return {k: v for k, v in os.environ.items() if not k.startswith("GIT_")}
Comment on lines +220 to +221
# Git exports GIT_DIR and GIT_INDEX_FILE to hooks, and neither cwd nor `git -C` overrides them:
# under the pre-commit hook every call below would otherwise act on the committing repository.
@codecov

codecov Bot commented Sep 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 62.26%. Comparing base (814f7a5) to head (956e505).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1807   +/-   ##
=======================================
  Coverage   62.26%   62.26%           
=======================================
  Files          84       84           
  Lines       21558    21558           
  Branches     3188     3188           
=======================================
  Hits        13423    13423           
  Misses       5937     5937           
  Partials     2198     2198           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants